import requests
def get_user_info(uid):
    """
    根据uid获取用户基本信息。
    B站未直接提供API查询直播间ID，但可通过用户主页信息间接获取。
    """
    api_url = f"https://api.bilibili.com/x/space/wbi/acc/info?mid={uid}"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
    }
    response = requests.get(api_url, headers=headers)

    if response.status_code == 200:
        data = response.json()
        # 假设直播间链接存在于某个字段中，这里以示例说明，实际可能不同
        if 'live_room' in data and 'url' in data['live_room']:
            live_room_url = data['live_room']['https://live.bilibili.com/9527']
            # 提取直播间ID，通常直播间URL形如 https://live.bilibili.com/room/ROOM_ID
            room_id = live_room_url.split('/')[-1]
            return room_id
        else:
            return None
    else:
        print(f"请求失败，状态码：{response.status_code}，UID：{uid}")
        return None


uids = range(1, 11)  # 从1到10的uid
for uid in uids:
    room_id = get_user_info(uid)
    if room_id:
        print(f"UID {uid} 的直播间ID为: {room_id}")
    else:
        print(f"UID {uid} 没有找到对应的直播间信息")